# !/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:zzly
@file:serializers.py
@time:2020/09/08
"""
from rest_framework import serializers
from apps.adorn_process.models import AdornProcess
from apps.member.article.serializers import ArticleAppSeializer


class AdornProcessAppSeializer(serializers.ModelSerializer):
    class Meta:
        model = AdornProcess
        fields = ('id', 'title', 'notes', 'bg_color', 'icon')


class AdornProcessDetailAppSeializer(serializers.ModelSerializer):
    thumbnail = serializers.SerializerMethodField(read_only=True)
    related_articles = serializers.SerializerMethodField()

    def get_related_articles(self, obj):
        return ArticleAppSeializer(obj.related_articles.all(), many=True).data

    def get_thumbnail(self, obj):
        if obj.thumbnail:
            return obj.thumbnail.get_url()
        return ''

    class Meta:
        model = AdornProcess
        fields = ('id', 'title', 'notes', 'thumbnail', 'describe', 'icon', 'related_articles')
